package com.nulldev.util.networking.rudp;

import java.util.Arrays;

public class SplitMessage implements Comparable<SplitMessage> {
	private int sequenceID;
	private byte[] data;
	private long createTime;

	public SplitMessage() {
	}

	public SplitMessage(int sequenceID, byte[] data) {
		this.sequenceID = sequenceID;
		this.data = data;
		createTime = System.currentTimeMillis();
	}

	public void setValues(int sequenceID, byte[] data) {
		this.sequenceID = sequenceID;
		this.data = data;
		createTime = System.currentTimeMillis();
	}

	public int getSequenceID() {
		return sequenceID;
	}

	public byte[] getData() {
		return data;
	}

	public long getCreateTime() {
		return createTime;
	}

	@Override
	public int compareTo(SplitMessage o) {
		return this.sequenceID > o.sequenceID ? -1 : this.sequenceID < o.sequenceID ? 1 : 0;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (o == null || getClass() != o.getClass())
			return false;

		SplitMessage that = (SplitMessage) o;

		if (sequenceID != that.sequenceID)
			return false;
		if (!Arrays.equals(data, that.data))
			return false;

		return true;
	}

	@Override
	public int hashCode() {
		int result = sequenceID;
		result = 31 * result + Arrays.hashCode(data);
		return result;
	}
}
